package com.fpost.util;

import java.util.ArrayList;
import java.util.List;

import com.fpost.domain.ArticleType;
import com.fpost.form.dto.ArticleTypeDTO;
import com.fpost.manager.ArticleTypeManager;

public class FpostCache {
	
	private static FpostCache instance;
	private List<ArticleTypeDTO> articleTypeDTOList;
	
	private FpostCache() {
		setArticleTypeDTOList();
	} 
	
	public static synchronized FpostCache getInstance() {
		if (instance == null) {
			 instance = new FpostCache();
		}
		return instance;
	}

	public List<ArticleTypeDTO> getArticleTypeDTOList() {
		return articleTypeDTOList;
	}

	private void setArticleTypeDTOList() {		
		List<ArticleType> articleTypes = new ArticleTypeManager().getAll();
    	List<ArticleTypeDTO> articleTypeDTOList = new ArrayList<ArticleTypeDTO>();
    	for (ArticleType articleType : articleTypes) {
    		articleTypeDTOList.add(
    				new ArticleTypeDTO(String.valueOf(articleType.getArticleTypeId()), articleType.getArticleType()));
    	}		
		this.articleTypeDTOList = articleTypeDTOList;
	}

}
